package sort;

//https://www.sohu.com/a/246785807_684445
//https://blog.csdn.net/nrsc272420199/article/details/82587933
public class Quick {
    public static void main(String[] args) {
        int[] ints = {50,8,75,54,78,24,64,99};
        sort(ints,0,ints.length-1);
        for (int i = 0; i < ints.length; i++) {
            System.out.println(ints[i]);
        }

    }


    public static void sort(int[] ints,int low,int high){
        if (low < high){//
            int quick = quick(ints, low, high);//获取第一次排序后的中间值下标，中间值下标左边为小于ints[quick]的值
            //分治
            sort(ints,low,quick-1);
            sort(ints,quick+1,high);
        }
    }

    public static int quick(int[] ints,int low,int high){
        int temp = ints[low];
        while (low < high){
            while (low < high && ints[high] >= temp){
                high --;
            }
            ints[low] = ints[high];

            while (low < high && ints[low] <= temp){
                low ++;
            }
            ints[high] = ints[low];
        }
        ints[low] = temp;
        return low;
    }

    public static void quick(int[] arr){

    }
}
